import { Injectable } from '@nestjs/common';
import * as xlsx from 'xlsx';
@Injectable()
export class ExcelService {
    async exportExcel(data: any[], fileName: string): Promise<Buffer> {
        const worksheet = xlsx.utils.json_to_sheet(data);
        worksheet['!pageSetup'] = {
            paperSize: 'A4',
            // 其他任意需要设置的页面属性
        };
        worksheet['A1'].s = {
        fill: {
            fgColor: { rgb: "FFFFAA00" }
        },
        font: {
            name: "Arial",
            bold: true,
            color: { rgb: "FF000000" }
        }
        };
        const workbook = xlsx.utils.book_new();

        xlsx.utils.book_append_sheet(workbook, worksheet, 'Sheet1');

    const buffer = xlsx.write(workbook, {
      type: 'buffer',
      bookType: 'xlsx',
    });
    return buffer;
  }
}
